<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的草稿</title>
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layui/css/modules/layer/default/layer.css">
    <link rel="stylesheet" href="../../CSS/media.css">
    <style>
        .layui-card-header {
            font-size: 18px;
        }

        .layui-col-md3 .layui-panel {
            height: 240px;
            box-shadow: 0px 0px 10px 5px #aaa;
            padding: 0px;
            border-radius: 5px;
            background-color: #00F7DE;
        }

        .layui-panel .layui-sys-title {
            height: 40px;
            /*vertical-align:middle;*/
            line-height: 40px;
            width: 100%;
            background-color: #ffffff;
            font-size: 18px;
        }

        .layui-sys-title img {
            /*line-height: 40px;*/
            vertical-align: middle;
            /*float: right;*/
        }

        .draft .layui-tab-title {
            border-bottom-style: none;
            height: 70px;
            line-height: 70px;
            width: 50%;
            display: inline-block;
        }

        .draft .layui-tab-title li {
            font-size: 18px;
            font-weight: bold;
            color: #868686;
            border-right: 2px #9c9c9c solid;
            line-height: 30px !important;
        }

        .draft .layui-tab-title li:last-child {
            border-right: none !important;
        }

        .draft .layui-this {
            color: #1E9FFF !important;
        }

        .draft .layui-this:after {
            border-bottom: 0px !important;
        }

        .s_btn {
            width: 40%;
            float: right;
            position: relative;
            margin-top: 15px;
        }

        .s_btn i {
            font-size: 28px;
            color: #fff;
            position: absolute;
            cursor: pointer;
            background: #1E9FFF;
            text-align: center;
            border-top-right-radius: 5px;
            border-bottom-right-radius: 5px;
            padding: 4px;
        }

        .s_btn input {
            height: 40px;
            background: #f1f1f1;
            border: none;
            font-size: 16px;
            width: 80%;
            display: inline-block;
        }

        .layui-col2 {
            height: 260px;
            flex: 0 0 30%;
            padding-right: 10px;
            padding-left: 10px;
            cursor: pointer;
            box-sizing: border-box;
        }

        .layui-col img, .layui-col2 img {
            width: 100%;
        }

        .draft {
            width: 100%;
        }

        .draft_list {
            display: flex;
            width: 100%;
            flex-wrap: wrap;
            margin-top: 20px;
        }


        .draft_list_imfor_data > div {
            float: right;
            margin-right: 10px;
        }

        .layui-col2-card {
            box-shadow: 0 4px 11px 0px #bbbbbb;
            position: relative;
        }
        .app_list_imfor_name {
            display: inline-block;
            width: 55%;
            max-width: 190px;
            height: 40px;
            float: left;
            line-height: 40px;
            text-indent: 10px;
            font-weight: bold;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
        }

        .app_list_imfor_data {
            display: inline-block;
            width: 45%;
            height: 40px;
            line-height: 40px;
        }

        .app_list_imfor_data > div {
            float: right;
            margin-right: 10px;
        }
        .nav{
            display: none;
            width: 80px;
            height: 40px;
            background: #1E9FFF;
            position: absolute;
            color: #fff;
            text-align: center;
            padding: 8px 0px;
            box-sizing: border-box;
            border-radius: 4px;
        }
        .nav li{
            height: 27px;
            line-height: 27px;
            cursor: pointer;
        }
        .nav li:hover{
            text-decoration: underline;
        }
        .navHandel{
            height: 30px !important;
            width:30px!important;
            position: absolute;
            right:0px;
            bottom: 50px;
        }
    </style>
</head>
<body>
<div class="layui-tab layui-tab-brief draft" lay-filter="draft">
    <ul class="layui-tab-title">
        <li class="layui-this">应用</li>
        <li>模板</li>
        <li>数据</li>
        <li>样式</li>
    </ul>
    <div class="s_btn">
        <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input search">
        <i class="layui-icon ">&#xe615;</i>
    </div>
    <div class="layui-tab-content" style="background-color: #ffffff;">
        <div class="layui-tab-item layui-show app">
            <div class="draft_list"></div>
        </div>
        <div class="layui-tab-item mould">
            <div class="draft_list"></div>
        </div>
        <div class="layui-tab-item data">
            <div class="draft_list"></div>
        </div>
        <div class="layui-tab-item style">
            <div class="draft_list"></div>
        </div>
    </div>
</div>

<!--菜单-->
<ul class="nav">
    <li onclick="f_Cancel(this)">取消收藏</li>
</ul>
</body>

<script src="./../../JS/jquery-2.0.3.js"></script>
<script src="../../node_modules/iframeResizer.contentWindow.js"></script>
<script src="../../layui/layui.js" charset="utf-8"></script>
<script src="./../../layui/lay/modules/layer.js"></script>
<script>
    $(function () {
        //点击列表跳转详情页
        $('.draft_list').on('click','.layui-col2-card',function (e) {
            e = e || window.event;
            if (e.target.className === 'navHandel') return;
            //获取当前样式的id
            var id = $(this).attr('cId');
            parent.parent.document.getElementById('view').src = "HTML/comment.html?id="+id+'&type='+tabHandle;
        })

        //点击其他地方菜单栏隐藏
        $(document).click(function (e) {
            if ($('.nav').css('display') !== 'none') {
                e = e || window.event;
                if (e.target.className !== 'navHandel'){
                    $('.nav').hide();
                }
            }
        })
    })

    var tabHandleArr = [0];
    var tabHandle = 0;//当前点击的tab下标
    var favourUrl = ['/app/selFavourList','/template/selFavourList','/data/selFavourList','/style/selFavourList'];
    var param = {
        'condition': {
            'userid': parent.parent.getLocalStorage('JSXM').id,
        },
    };
    var flow = null;
    layui.use(['element','flow'], function () {
        var element = layui.element;
        flow = layui.flow;
        element.on('tab(draft)', function(data){
            tabHandle = data.index;
            if (tabHandleArr.indexOf(data.index) === -1) {
                var type = ['app','mould','data','style'];
                parent.parent.getFlowDataByPost(parent.parent.defaultUrl+favourUrl[data.index],param,1,flow,getList,type[data.index],0);
                tabHandleArr.push(data.index);
            }
        });

        //调用获取数据接口
        parent.parent.getFlowDataByPost(parent.parent.defaultUrl+'/app/selFavourList',param,1,flow,getList,'app',0);
    });

    //根据数据生成html
    function getList(data,type,type2) {
        if (type2) {
            $('.'+type).find('.draft_list').html('');
        }
        var html = ''
        for (var i = 0,l = data.length;i<l;i++) {
            var img = data[i].img || (data[i].content && JSON.parse(data[i].content).img) ;
            html += '            <div class="layui-col2">\n' +
                '                <div cId="'+data[i].id+'" class="layui-col2-card" style="position: relative;">\n' +
                '                    <img class="AppImg" src="'+img+'">\n' +
                '                    <img class="navHandel" src="../../static/IMG/Common/editor.png" onclick="showNav(this,\''+data[i].id+'\',\''+type+'\');" />\n' +
                '                    <div class="app_list_imfor">\n' +
                '                        <div class="app_list_imfor_name">'+data[i].name+'</div>\n' +
                '                        <div class="app_list_imfor_data">\n' +
                '                            <div class="comments">\n' +
                '                                <i class="layui-icon">&#xe63a;</i><!--评论-->\n' +
                '                                <span>'+data[i].commentnum+'</span>\n' +
                '                            </div>\n' +
                '                            <div class="icon-socre">\n' +
                '                                <i class="layui-icon">&#xe67b;</i><!--评分-->\n' +
                '                                <span>'+data[i].score+'</span>\n' +
                '                            </div>\n' +
                '                            <div class="collect">\n' +
                 '<span class="iconfont iconshoucang" style="font-size: 20px; color:#c00"></span>'+
                '                            </div>\n' +
                '                        </div>\n' +
                '                    </div>\n' +
                '                </div>\n' +
                '            </div>'
        }
        html +=   '</div>'
        $('.'+type).find('.draft_list').append(html);
    }
    
    //取消收藏
    var unfavourUrl = ['/app/delFavourById', '/template/delFavourById', '/data/delFavourById', '/style/delFavourById', ''];
    function f_Cancel(obj) {
        var id = $(obj).parent().attr('key');
        var type = $(obj).parent().attr('type');
        parent.parent.ajaxGet(parent.parent.defaultUrl+unfavourUrl[tabHandle],{'id':id},function (data) {
            if (data.code === 200) {
                parent.layer.msg('操作成功');
                parent.parent.getFlowDataByPost(parent.parent.defaultUrl+favourUrl[tabHandle],param,1,flow,getList,type,1);
                $('.nav').hide();
            } else if (data.message) {
                parent.layer.msg(data.message)
            }
        })
    }

    //编辑按钮
    function showNav(obj,id,type) {
        var left = $(obj).offset().left - 80;
        var top = $(obj).offset().top - 13;
        $('.nav').show().css({'left':left,'top':top}).attr({'key':id,'type':type});
    }
</script>
</html>